<template>
  <div class="main member-list">
    <div class="filter-container">
      <el-input @keyup.enter.native="search" class="filter-item" placeholder="按手机号搜索" v-model="mobile"></el-input>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
    </div>
    <el-table :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border highlight-current-row>
      <el-table-column align="center" label="手机号" prop="mobile"></el-table-column>
      <el-table-column align="center" label="昵称" prop="nickname"></el-table-column>
      <el-table-column align="center" label="性别">
        <template slot-scope="scope">
          <span v-text="sexes[scope.row.sex]"></span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="会员等级">
        <template slot-scope="scope">
          <span v-text="levels[scope.row.role]"></span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="级别">
        <template slot-scope="scope">
          <span>
            Lv{{scope.row.subdivisionLevel}}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作状态">
        <template slot-scope="scope">
          <span>{{scope.row.deleteFlag===0?'禁用':'启用'}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作时间">
        <template slot-scope="scope">
          <div class="text-justify">
            <p v-text="formatDate(scope.row.updatedAt, 'YYYY-MM-DD HH:mm:ss')"></p>
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作账号" prop="operator"></el-table-column>
      <el-table-column align="center" label="操作" width="180">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="dialogLook(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container" v-if="total > 0">
      <el-pagination @current-change="handleCurrentChange" :current-page.sync="page" :page-size="pageSize" :total="total" layout="total, prev, pager, next, jumper"></el-pagination>
    </div>
    <el-dialog title="查看" :visible.sync="showEditPop">
      <el-form :model="dialogData"   size="medium" label-width="120px">
        <el-form-item label="操作账号:">
           <span>{{dialogData.operator}}</span>
        </el-form-item>
        <el-form-item label="钉钉审批号:"  >
            <span>{{dialogData.dingDingNo}}</span>
        </el-form-item>
        <el-form-item label="提交申请者:"  >
            <span>{{dialogData.proposer}}</span>
        </el-form-item>
        <el-form-item label="禁用原因:" >
             <span>{{dialogData.reason}}</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
          <el-button @click="showEditPop = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
  
</template>

<script>
export default {
  name: 'memberList',
  data() {
    return {
      list: [],
      mobile: '',
      page: 1,
      pageSize: 20,
      total: 0,
      // 性别
      sexes: {
        '0': '保密',
        '1': '男',
        '2': '女'
      },
      // 会员等级
      levels: {
        '0': '普通用户',
        '1': '兰蜜',
        '2': '大区',
        '3': '董事'
      },
      listLoading: false,
      showEditPop: false,
      dialogData: {} 
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.listLoading = true
      this.request({    
        url: '/bsnl-member/member/status/log/list',
        method: 'post',
        data: {
            mobile: this.mobile,
            page: this.page,
            pageSize: this.pageSize
        }
      })
        .then(({ rows, total }) => {
          this.list = rows
          this.total = total
          this.listLoading = false
        })
        .catch(err => {
          console.log(err)
          this.list = []
          this.total = 0
          this.listLoading = false
        })
    },
    // 搜索
    search() {
      this.page = 1
      this.getList()
    },
    // 切换分页
    handleCurrentChange(page) {
      this.page = page
      this.getList()
    },
    dialogLook(row) {
        this.dialogData = row
        this.showEditPop = true
    }
  }
}
</script>
